import Vue from 'vue'
import VueRouter from 'vue-router'
import login from '../mianjing/login.vue'
import register from '../mianjing/register.vue'
import layout from '../mianjing/layout.vue'
import article from '../mianjing/sub/artilce.vue'
import collect from '../mianjing/sub/collect.vue'
import like from '../mianjing/sub/like.vue'
import my from '../mianjing/sub/my.vue'
import detail from '../mianjing/detail.vue'


Vue.use(VueRouter)

//路由规则配置
const routes = [
  //一个路径对应一个组件
  {
    path: '/login',
    name: 'login',
    component: login
  },
  {
    path: '/register',
    name: 'register',
    component: register
  },
  {
    path: '/detail/:id',
    name: 'detail',
    component: detail
  },
  {
    path: '/layout',
    name: 'layout',
    component: layout,
    redirect: '/layout/home',
    children: [
      /**
     1.如果写了/,那就跟一级路由地址没有关系,
     如果没有写,那就会和一级路由地址进行拼接
    2.如果子路由path,没有添加/,那么重定向中需要加上/layout来表示
    是谁的子路由,在router-link的to属性中,也需要拼接完整路由地址
 **/
      // {
      //   path: 'home',
      //   name: '面经',
      //   component: article,
      // },
      // {
      //   path: 'collect',
      //   name: '收藏',
      //   component: collect,
      // },
      // {
      //   path: '/like',
      //   name: '喜欢',
      //   component: like,
      // },
      // {
      //   path: '/my',
      //   name: '我的',
      //   component: my,
      // },

      {
        path: '/layout/home',
        name: 'article',
        component: article,
        meta: {
          keepalive: true
        }
      },
      {
        path: '/layout/collect',
        name: 'collect',
        component: collect,
      },
      {
        path: '/layout/like',
        name: 'like',
        component: like,
      },
      {
        path: '/layout/my',
        name: 'my',
        component: my,
        meta: {
          keepalive: true
        }
      },

    ]
  },



]

const router = new VueRouter({
  mode: 'hash',//配置路由模式
  routes,
  linkActiveClass: 'active',//模糊匹配类名
  linkExactActiveClass: 'Thenactive',//精准匹配类名
})

export default router
